package com.qf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.qf.entity.GoodsType;
import com.qf.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import sun.awt.image.PNGImageDecoder;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 你的名字
 * @Date: 2021/07/07/21:22
 * @Description:
 */
@Controller
@RequestMapping("goodsType")
public class GoodsTypeController {
    @Autowired
    private GoodsTypeService goodsTypeService;

    @RequestMapping("/getGoodsTypeList")
    @ResponseBody
    public List<GoodsType> getGoodsTypeList(){
        List<GoodsType> list = goodsTypeService.list();
        return list;
    }

    @RequestMapping("/addGoodsType")
    @ResponseBody
    public boolean  addGoodsType(@RequestBody GoodsType goodsType){
        boolean save = goodsTypeService.save(goodsType);

        return save;
    }
    @RequestMapping("/getGoodsTypeByPid/{pid}")
    @ResponseBody
      public List<GoodsType> getGoodsTypeByPid(@PathVariable(value = "pid") Integer pid){
        QueryWrapper<GoodsType> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_type_pid", pid);
        List<GoodsType> goodsTypeList = goodsTypeService.list(wrapper);
        return  goodsTypeList;
    }
    @RequestMapping("/delNodes/{id}")
    @ResponseBody
   public  boolean deleteNode(@PathVariable(value = "id") Integer id){
        boolean b = goodsTypeService.removeById(id);
        return b;
    }
    @RequestMapping("updateNode")
    @ResponseBody
    public boolean updateNode(@RequestBody GoodsType goodsType){
        boolean b = goodsTypeService.updateById(goodsType);
        return b;
    }
    @RequestMapping("/moveNodes/{trId}/{tarId}")
    @ResponseBody
    public boolean moveNodes(@PathVariable(value = "trId") Integer trId, @PathVariable(value = "tarId") Integer tarId){
        UpdateWrapper<GoodsType> wrapper = new UpdateWrapper<>();
       wrapper.setSql("goods_type_pid="+tarId);
       wrapper.eq("id",trId);
        boolean b = goodsTypeService.update(wrapper);
        return b;
    }
}
